//获取应用实例
const app = getApp()

Page({
  data: {
    payFocus: false, //文本框焦点
    firstPayPassword: false,
    secondPayPassword: false,
    newpassword: '',
    agangpassword: '',
    sixteenS: '发送验证码',
    sms: ''
  },
  onLoad: function () {
    // this.showInputLayer();
  },
  /**
   * 显示支付密码输入层
   * 原始密码
   */
  showInputLayer: function () {
    this.setData({
      firstPayPassword: true,
      payFocus: true
    });
  },
  showfirst: function () {
    this.setData({
      firstPayPassword: true,
      payFocus: true
    })
  },
  /**
   * 获取焦点
   */
  getFocus: function () {
    this.setData({
      payFocus: true
    });
  },
  /**
   * 输入密码监听
   * 老
   */
  inputPwd: function (e) {
    this.setData({
      pwdVal: e.detail.value
    });
    if (e.detail.value.length >= 6) {
      this.setData({
        oldPayPassword: false,
        payFocus: true,
        pwdVal: this.data.pwdVal,
        firstPayPassword: true
      });
    }
  },
  /**
   * 输入密码监听
   * 新1
   */
  inputPwdNewOne: function (e) {
    this.setData({
      newpassword: e.detail.value
    });
    if (e.detail.value.length >= 6) {
      this.setData({
        firstPayPassword: false,
        payFocus: true,
        secondPayPassword: true
      });
    }
  },
  /**
   * 输入密码监听
   * 新2
   */
  inputPwdNewTwo: function (e) {
    this.setData({
      agangpassword: e.detail.value
    });
    if (e.detail.value.length >= 6) {
      if (this.data.agangpassword != this.data.newpassword) {
        wx.showToast({
          title: '密码输入不一致',
          icon: 'none'
        })
        setTimeout(function (params) {
          wx.navigateTo({
            url: '../setUp/setUp',
          })
        }, 1000)
      } else {
        wx.request({
          url: app.globalData.baseUrl + '/user/getSMSUpdatePaymentCode',
          data: {
            xcxOpenId: app.globalData.xcxOpenId,
            paymentCode: this.data.newpassword
          },
          method: 'POST',
          header: {
            'content-type': 'application/x-www-form-urlencoded' // 默认值
          },
          success: function (res) {
            if (res.code == 0) {
              wx.showToast({
                title: '设置成功！'
              })
              setTimeout(function (params) {
                wx.navigateTo({
                  url: '../setPassword/setPassword',
                })
              }, 1000)
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
              setTimeout(function (params) {
                wx.navigateTo({
                  url: '../setUp/setUp',
                })
              }, 1000)
            }
          }
        })
      }
    }
  },
  havaSms: function () {
    if (this.data.sixteenS == '发送验证码') {
      wx.request({
        url: app.globalData.baseUrl + '/user/resetPaymentCodeSendSMS',
        data: {
          xcxOpenId: app.globalData.xcxOpenId
        },
        method: 'post',
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success: function (res) {
          if (res.data.code == 0) {
            var s = 60
            that.setData({
              sixteenS: s + 's'
            })
            let time = setInterval(function () {
              that.setData({
                sixteenS: --s + 's'
              })
              if (s == 0) {
                clearInterval(time)
                that.setData({
                  sixteenS: '发送验证码'
                })
              }
            }, 1000)
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        }
      })
    }
  },
  istrueSms: function () {
    if (this.data.sms == '') {
      wx.showToast({
        title: '请输入验证码！',
        icon: none
      })
      return
    }
    wx.request({
      url: app.globalData.baseUrl + '/user/resetPaymentCodeVerifySMS',
      data: {
        xcxOpenId: app.globalData.xcxOpenId,
        code: this.data.sms
      },
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        if (res.data.code == 0) {
          this.showInputLayer();
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      }
    })
  }
})